const vm = new Vue({
    el: '#root',
    data: {
        nm: '',
        pwd: '',
        sex: '女',
        age: 5,
        city: '北京',
        na: '',
        pw: '',
        ag: '',
        todo: localStorage.getItem('todo') ? JSON.parse(localStorage.getItem('todo')) : [],
        all: false,
        lessons: [],
    },
    methods: {

        del(index) {
            // filter
            this.todo.splice(index, 1)
        },
        onEnter(evt) {
            if (this.nm !== '' && this.pwd !== '' && this.sex !== '' && this.age !== '' && this.city !== '') {
                let res = { nm: this.nm, pwd: this.pwd, sex: this.sex, age: this.age, city: this.city }
                this.todo.push(res);
                localStorage.setItem('todo', JSON.stringify(this.todo))
            } else {
                alert('输入错误')
            }

        },
        name() {
            let amg = /^\w{2,5}$/;
            if (amg.test(this.nm)) {
                this.na = '格式正确'
            } else {
                this.na = '格式错误'
                this.nm = ''
            }
        },
        pwd1() {
            let amg = /^\w{2,5}$/
            if (amg.test(this.pwd)) {
                this.pw = '格式正确'
            } else {
                this.pw = '格式错误'
                this.pwd = ''
            }
        },
        ages() {
            if (+this.age >= 1 && +this.age <= 200) {
                this.ag = '年龄验证通过'
            } else {
                this.ag = '请认真填写您的年龄'
            }
        },

        allfn() {
            if (this.all) {

                this.todo.forEach((item, index) => {
                    this.lessons.push(String(index));
                });
                console.log(this.lessons);
            } else {
                this.lessons = []
            }
        },

        selectfn() {
            this.all = this.lessons.length = this.todo.length-2
        }

    }
})